#include <iostream>
using namespace std; 

int main()
{
    int casenum = 0;
    cin >> casenum; 
    
    int m, n;
    bool first = true;
    while (cin >> m >> n)
    {
        if (!first) cout << endl; 
        else first = false;

        for (int i = 0; i < n; ++i)
        {
            if (i != 0) cout << endl; 
            for (int j = 1; j <= m; ++j)
            {
                for (int k = 0; k < j; ++k) 
                    cout << j; 
                cout << endl; 
            }
            for (int j = m - 1; j > 0; --j)
            {
                 for (int k = 0; k < j; ++k)
                      cout << j;
                 cout << endl; 
            }
        }
    }
}
